import React from 'react';
import { getSalaryStandByPostCodes } from '@/services/organization';

// 获取薪资参考映射表
const useSalaryStandByPostCodes = query => {
    const [data, setData] = React.useState([]);
    const [loading, setLoading] = React.useState(false);
    const [message, setMessage] = React.useState(null);

    const fetchData = async () => {
        setLoading(true);

        const { data: datalist, code, msg } = (await getSalaryStandByPostCodes(query)) || {};

        if (code === 10000) {
            setData(datalist);
        }

        setMessage(msg);

        setLoading(false);
    };

    React.useEffect(() => {
        if (query) {
            fetchData();
        }
    }, [query]);

    return [loading, data, message];
};

export default useSalaryStandByPostCodes;
